package com.yichat.micro.msghttpservice;

import com.yichat.micro.msghttpservice.common.Constants;
import com.yichat.micro.msghttpservice.common.util.JsonUtil;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by chenmohan on 2019/04/03
 *
 * @description 测试接口，回调接口
 */
@RestController
public class TestController {

    @RequestMapping("/foo")
    public Foo test(HttpServletRequest req, Foo student) throws InterruptedException {
        // Thread.sleep(3000);
        student.setTotal(student.getA() + student.getB());
        System.out.println("【响应了】");
        return student;
    }

    @RequestMapping("/data")
    public String callBack(@RequestBody String data) {
        Foo foo = JsonUtil.toBean(data, Foo.class);
        System.err.println(foo);
        return Constants.ok;
    }

    @Data
    public static class Foo {
        private String name;
        private Integer age;
        private Integer a;
        private Integer b;
        private Integer total;
    }

}
